package xyz.lhou.view;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import xyz.lhou.empty.Person;
import xyz.lhou.mapper.PersonMapper;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * 主界面
 *
 * @author L3476
 */
public class MainView {
    private JButton buttonSql;
    private JPanel panel1;
    private JButton buttonService;
    private JTextField textField1;
    private PersonMapper personMapper;

    public void startView() {
        JFrame frame = new JFrame("四方");
        frame.setSize(1600, 1400);
        frame.setContentPane(panel1);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);

        long startTime = System.currentTimeMillis();
        ApplicationContext applicationContext = new FileSystemXmlApplicationContext("classpath:spring.xml");
        long endTime = System.currentTimeMillis();
        System.out.println("springContext 加载时间:"+ (startTime - endTime));
        personMapper = applicationContext.getBean(PersonMapper.class);

        textField1.setText("springContext 加载时间："+(startTime - endTime));


        buttonSql.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                System.out.println("单机按钮");
                Integer id = 1;
                Person person = personMapper.selectById(id);
                System.out.println(person.toString());
            }
        });

    }
}
